<?php
@$msg=$_REQUEST['msg'];
@$m=$_REQUEST['m'];
echo @$m;
echo @$msg;
mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("chat")or die(mysql_error());

if (isset($_POST['submit'])) {
	$email=$_POST['email'];
	$pass=$_POST['password'];
	$sql= mysql_query("select * from users where u_email='$email' and u_password='$pass'")or die(mysql_error());
	if(mysql_num_rows($sql) > 0)
	{
	$row = mysql_fetch_array($sql);
	session_start();
	$_SESSION['u_id']=$row['u_id'];
	$_SESSION['u_name'] = $row['u_name'];
    $_SESSION['u_email'] = $row['u_email'];
	$_SESSION['group'] = $_POST['group'];
    
	header('location:chatwindow.php');
	} else{
		echo "invalid user";
	}

}
?>
<html>
	
</html>
<link rel="stylesheet" type="text/css" href="bootstrap.css">

<form method="post" action="">
	<table width="40%" align="left">
		<tr>
			<td colspan="2" align="center"><h1>Login</h1></td>
		</tr>
		<tr>
			<td>Email</td>
			<td><input type="email" name="email" placeholder="Yor Email" required="true"/></td>
		</tr>
		<tr>
			<td>Password</td>
			<td><input type="password" name="password" placeholder="Password" required="true"/></td>
		</tr>
		<tr>
			<td>Join Chatroom</td>
				<td>
					<select name="group">
            <option value="">--- Select ---</option>
            <?php
            $SQL= mysql_query("SELECT * FROM user_group")or die(mysql_error());
			while($data=mysql_fetch_assoc($SQL))
						{ ?>
            <option value="<?php echo $data['group_id'] ?>"</option>
			<?php echo $data['g_name'] ?>
            <?php
            } ?>
		</tr>
		<tr>
			<td colspan="2" align="center"><input type="submit" name="submit" value="Login" /></td>
		</tr>
	
	</table>
</form>
<form name="ragister" method="post" action="register.php">
	<table align="right" width="40%" >
		<tr>
			<td colspan="2"><h1>User Ragisteration</h1></td>
		</tr>
		<tr>
			<td>Name</td>
			<td><input type="text" name="name"placeholder="Your Nane" required="true"/></td>
		</tr>
		<tr>
			<td>Email</td>
			<td><input type="email" name="email" placeholder="Your Email" required="true" /></td>
		</tr>
		<tr>
			<td>Mobile</td>
			<td><input type="tel" name="mobile" placeholder="Your 10digit mobile" /></td>
		</tr>
		<tr>
			<td>Password</td>
			<td><input type="password" name="password" placeholder="password"  required="true"/></td>
		</tr>
		<tr>
			<td>Join Group</td>
				<td>
					<select name="group">
            <option value="">--- Select ---</option>
            <?php
            $SQL= mysql_query("SELECT * FROM user_group")or die(mysql_error());
			while($data=mysql_fetch_assoc($SQL))
						{ ?>
            <option value="<?php echo $data['group_id'] ?>"</option>
			<?php echo $data['g_name'] ?>
            <?php
            } ?>
		</tr>
		
		
		<tr>
			<td colspan="2" align="center"><input type="submit" /></td>
		</tr>
		
	</table>
	
</form>